package com.ypan.mail.controller;

import com.ypan.mail.entity.MailEntity;
import com.ypan.mail.service.MailService;
import com.ypan.mail.utils.IpUtil;
import com.ypan.mail.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @Author ypan
 * @Date on 2021/3/17  11:08
 * @Desc
 */
@Slf4j
@RestController
@RequestMapping("/mail")
public class MailController {

    @Autowired
    private MailService mailService;

    @GetMapping("sendMail")
    public JsonResult sendMail(@Valid MailEntity mailEntity, HttpServletRequest request){
        log.info("调用ip:{} 调用方:{} 接收方:{} 标题:{} 内容:{}", IpUtil.getIpAddr(request),mailEntity.getCaller(),mailEntity.getMail(),mailEntity.getTitle(),mailEntity.getContent());
        return mailService.send(mailEntity);
    }
}
